﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FFIV.Lib.IView.Categories;
using FFIV.Lib.Model;
using FFIV.Lib.Utilities;

public partial class Views_Categories_Detail : UserControl, IDetailCategory
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}

	public CategoryNode Categories
	{
		set
		{
			tv_Categories.Nodes.Clear();
			BuildCategoryTreeView(value.Children, tv_Categories.Nodes);
			tv_Categories.ExpandAll();
		}
	}

	private void BuildCategoryTreeView(IEnumerable<CategoryNode> datas, TreeNodeCollection items)
	{
		foreach (CategoryNode data in datas)
		{
			TreeNode item = new TreeNode();
			item.Text = string.Format("{0} ({1})", data.Name, data.ArticleCount);
			item.Value = data.Id.ToString();
			// 点击跳转到该列表详细
			item.NavigateUrl = UrlUtility.GetCategoriesUrl(data.Id);

			items.Add(item);

			BuildCategoryTreeView(data.Children, item.ChildNodes);
		}
	}
}
